/************************************************************
wx
2020/1/18
角色通用属性部分 
*************************************************************/

using System.Collections.Generic;
using UnityEngine;

public abstract partial class Character
{
    protected int m_levelMax = 0;

    public string Name { get; protected set; }
    public int Hp { get; protected set; } = 0;
    public int HpMax { get; protected set; } = 0;
    public int Level { get; protected set; } = 0;
    public int Mp { get; protected set; } = 0;
    public int MpMax { get; protected set; } = 10;
    public int Attack { get; protected set; } = 0;
    public int Defend { get; protected set; } = 0;
    public CharacterType Type { get; protected set; }

    private bool m_bDied = false;

    public void HpChange(int change)
    {
        if (m_bDied || change == 0)
            return;

        Hp += change;
        if (Hp > HpMax)
        {
            Hp = MpMax;
        }

        if (Hp <= 0)
        {
            Hp = 0;
            m_bDied = true;
            //todo send die msg
            Debug.Log($"{Name}死了");
        }

        if (change > 0)
        {
            Debug.Log($"{Name}的Hp增加{change},现在为{Hp}");
        }

        if (change < 0)
        {
            Debug.Log($"{Name}的Hp减少{-change},现在为{Hp}");
        }

        MessageManager.Instance.Excute(MessageType.UpdateFightUI);
    }

    public void MpChange(int change)
    {
        if (m_bDied || change == 0)
            return;

        Mp += change;
        Mp = Mathf.Clamp(Mp, 0, MpMax);

        if (change > 0)
        {
            Debug.Log($"{Name}的Mp增加{change},现在为{Mp}");
        }

        if (change < 0)
        {
            Debug.Log($"{Name}的Mp减少{-change},现在为{Mp}");
        }

        MessageManager.Instance.Excute(MessageType.UpdateFightUI);
    }

    public void AttackChange(int change)
    {
        if (m_bDied || change == 0)
            return;

        Attack += change;
        Attack = Mathf.Clamp(Attack, 0, Attack);

        if (change > 0)
        {
            Debug.Log($"{Name}的攻击力增加{change},现在为{Attack}");
        }

        if (change < 0)
        {
            Debug.Log($"{Name}的攻击力减少{-change},现在为{Attack}");
        }

        MessageManager.Instance.Excute(MessageType.UpdateFightUI);
    }

    public void DefendChange(int change)
    {
        if (m_bDied || change == 0)
            return;

        Defend += change;
        Defend = Mathf.Clamp(Defend, 0, Defend);

        if (change > 0)
        {
            Debug.Log($"{Name}的防御力增加{change},现在为{Defend}");
        }

        if (change < 0)
        {
            Debug.Log($"{Name}的防御力减少{-change},现在为{Defend}");
        }

        MessageManager.Instance.Excute(MessageType.UpdateFightUI);
    }
}

public enum CharacterType
{
    MainCharacter,
    Monster,
}
